/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.washington.apl.weather;

import edu.washington.apl.weather.WMR968;
import edu.washington.apl.weather.WeatherStation;
import edu.washington.apl.weather.WeatherUpdateEvent;
import edu.washington.apl.weather.transforms.RapidFire;
import edu.washington.apl.weather.transforms.Transform;
import edu.washington.apl.weather.util.WeatherProperties;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Copyright (c) 2012 Richard Vanderpool
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions: The above copyright
 * notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * @author Richard Vanderpool
 */
public class JWeatherUploader {

    WeatherProperties properties = WeatherProperties.getInstance();
    WeatherStation station = null;//new WMR968();

    public JWeatherUploader() {
        System.out.println("JWeatherUploader");
        System.out.println("written by Richard Vanderpool");
        if (properties.getBooleanProperty("station.wmr968.attached", false)) {
            station = new WMR968();
        }
        if (station == null) {
            System.err.println("No weather stations defined, please see weather.properties");
            System.exit(0);
            return;
        }
        station.setUpdateListener(new WeatherUpdateEvent() {
            @Override
            public void weatherEvent(WeatherStation station, long timeOfEvent) {
                Transform t = new RapidFire();
                System.err.println(t.transform(station));
            }
        });
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new JWeatherUploader();

        while (true) {
            try {
                Thread.sleep(1999);
            } catch (InterruptedException ex) {
                Logger.getLogger(JWeatherUploader.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
